import React, { Suspense } from 'react';
import {
    Switch,
    Route,
    Redirect,
} from "react-router-dom";
function RouterView({routeList}){
    return <Suspense fallback={<div>Loading..</div>}>
        <Switch>
            {
                routeList&&routeList.length>0?routeList.map((item,index)=>{
                    if(item.to){
                        return <Redirect key={index} to={item.to} />
                    }else{
                        return <Route 
                            key={index}
                            path={item.path}
                            render={routerProps=>{
                                return <item.component
                                    {...routerProps} 
                                />
                            }}
                        />
                    }
                }):null
            }
        </Switch>
    </Suspense>
};
export default RouterView;